package com.feitubc.tools.fileimport.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 自定义Spring辅助类，实现ApplicationContextAware，获取BeanFactory中的定义的对象和ApplicationContext
 * 
 * @author zhc
 * 
 * @see org.springframework.context.ApplicationContextAware
 */
public class SpringContextHelper implements ApplicationContextAware {

    private static ApplicationContext applicationContext = null;

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (SpringContextHelper.applicationContext == null) {
            SpringContextHelper.applicationContext = applicationContext;
        }
    }


    public static ApplicationContext getApplicationContext() {
        return SpringContextHelper.applicationContext;
    }


    public static Object getBean(String beanName) {
        return SpringContextHelper.applicationContext.getBean(beanName);
    }

}
